﻿using System;
using System.Collections.Generic;

namespace PokerManage
{
    public class Deck
    {
        public Card[] Cards = new Card[52];
        Random random = new Random();

        public Deck()
        {
            for (int i = 0; i < Cards.Length; i++)
            {
                Cards[i] = new Card { Image = $"pokers\\{i+1}.png" };
            }
        }

        public void Refresh()
        {
            var t = new Card[52];
            HashSet<int> indexes = new HashSet<int>();
            for (int i = 0; i < 52; i++)
            {
                int r;
                while (true)
                {
                    r = random.Next(0, 52);
                    if(!indexes.Contains(r))
                    {
                        break;
                    }
                }
                indexes.Add(r);
                t[i] = Cards[r];
            }
            Cards = t;
        }

        public Card[] GetCards(int order)
        {
            Card[] t = new Card[13];
            for (int i = 0; i < t.Length; i++)
            {
                t[i] = Cards[i + order * 13];
            }
            return t;
        }
    }
}
